//
//  AWImageChatMessage.m
//  AtWork2
//
//  Created by lucas on 15/5/28.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWImageChatMessage.h"

@implementation AWImageChatMessage

+ (instancetype)imageChatMessageWithFrom:(NSString *)from
                                  to:(NSString *)to
                             content:(NSData *)content
                        chatDescType:(AWChatDestType)chatDestType {
    return [[self alloc] initWithImageMessageWithFrom:from to:to content:content chatDescType:chatDestType];
}

- (instancetype)initWithImageMessageWithFrom:(NSString *)from
                                  to:(NSString *)to
                             content:(NSData *)content
                        chatDescType:(AWChatDestType)chatDestType {
    if (self = [super initWithFrom:from to:to messageType:AWMessageTypeChat]) {
        self.chatDestType = chatDestType;
        self.chatMessageType = AWChatMessageTypeImage;
        [self bodyWithKey:AWMessageKContent value:base64WithData(content)];
    }
    return self;
}

+ (instancetype)imageServeAppMessageWithFrom:(NSString *)from
                                          to:(NSString *)to
                                     content:(NSData *)content {
    return [[self alloc] initWithServeAppImageMessageWithFrom:from to:to content:content];
}

- (instancetype)initWithServeAppImageMessageWithFrom:(NSString *)from
                                                  to:(NSString *)to
                                             content:(NSData *)content {
    if (self = [super initWithFrom:from to:to messageType:AWMessageTypeServeNo]) {
        self.chatMessageType = AWChatMessageTypeImage;
        [self bodyWithKey:AWMessageKContent value:base64WithData(content)];
    }
    return self;
}

- (void)setMediaId:(NSString *)mediaId {
    [self bodyWithKey:AWMessageKMediaId value:mediaId];
}

- (NSString *)mediaId {
    return [self bodyValueForKey:AWMessageKMediaId];
}

- (NSData *)content {
    if ([self bodyValueForKey:AWMessageKContent]) {
        return base64WithString([self bodyValueForKey:AWMessageKContent]);
    }
    return [NSData data];
}


- (void)setPath:(NSString *)path {
    [self bodyWithKey:AWMessageKPath value:path];
}

- (NSString *)path {
    return [self bodyValueForKey:AWMessageKPath];
}

- (NSUInteger )contentHeight {
    return [[self bodyValueForKey:AWMessageKThumbHeight] longValue];
}

- (NSUInteger )contentWidth {
    return [[self bodyValueForKey:AWMessageKThumbWidth] longValue];
}

@end
